package com.mrjy.search.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.HotSearchKeywords;
import com.mrjy.search.bo.ISearchBo;

@Controller
@RequestMapping("/search")
public class SearchController {
	
	@Resource
	private ISearchBo searchBo;
	
	/**
	 * 导入solr
	 * @return
	 */
	@RequestMapping("/importSolr")
	@ResponseBody
	public Object importSolr() {
		return searchBo.importSolr();
	}
	
	
	/**
	 * 执行搜索
	 * @param q 用户输入的关键词
	 * @param page
	 * @param rows
	 * @param type 0--课程  1--明师  2--问答
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/doSearch")
	@ResponseBody
	public Object doSearch(String q,Integer type,Integer page, Integer rows,HttpServletRequest request,HttpServletResponse response,HttpSession session){
		return searchBo.doSearch(q,type,page,rows,request,response,session);
	}
	
	/**
	 * 查询用户搜索历史
	 * @param request
	 * @return
	 */
	@RequestMapping("/listSearchHistory")
	@ResponseBody
	public Object listSearchHistory(HttpSession session){
		return searchBo.listSearchHistory(session);
	}
	
	/**
	 * 删除用户搜索历史
	 * @param request
	 * @return
	 */
	@RequestMapping("/deleteSearchHistory")
	@ResponseBody
	public Object deleteSearchHistory(HttpSession session,Integer index){
		return searchBo.txDeleteSearchHistory(session,index);
	}
	
	/**
	 * 查询热搜 for weixin
	 * @param request
	 * @return
	 */
	@RequestMapping("/listHotSearch")
	@ResponseBody
	public Object listHotSearch(HttpSession session){
		return searchBo.listHotSearch(session);
	}
	
	/**
	 * 分页查询热搜 for back
	 * @param session
	 * @return
	 */
	@RequestMapping("/queryPage")
	@ResponseBody
	public Object queryPage(HttpSession session,HotSearchKeywords keywords){
		return searchBo.queryPage(session,keywords);
	}
	
	/**
	 * 添加热搜 for back
	 * @param session
	 * @param keywords
	 * @return
	 */
	@RequestMapping("/insertHotSearch")
	@ResponseBody
	public Object insertHotSearch(HttpSession session,HotSearchKeywords keywords){
		return searchBo.txInsertHotSearch(session,keywords);
	}
	
	/**
	 * 编辑热搜
	 * @param session
	 * @param keywords
	 * @return
	 */
	@RequestMapping("/updateHotSearch")
	@ResponseBody
	public Object updateHotSearch(HttpSession session,HotSearchKeywords keywords){
		return searchBo.txUpdateHotSearch(session,keywords);
	}
	
	/**
	 * 启用禁用
	 * @param session
	 * @param keywords
	 * @return
	 */
	@RequestMapping("/updateDisableFlag")
	@ResponseBody
	public Object updateDisableFlag(HttpSession session,HotSearchKeywords keywords){
		return searchBo.txUpdateDisableFlag(session,keywords);
	}
	
	/**
	 * 删除热搜
	 * @param session
	 * @param keywords
	 * @return
	 */
	@RequestMapping("/deleteHotSearch")
	@ResponseBody
	public Object deleteHotSearch(HttpSession session,HotSearchKeywords keywords){
		return searchBo.txDeleteHotSearch(session,keywords);
	}
	
	/**
	 * 导出exl
	 * @param session
	 * @param keywords
	 * @return
	 */
	@RequestMapping("/exportExl")
	@ResponseBody
	public Object exportExl(HttpSession session,HttpServletResponse response,HotSearchKeywords keywords){
		return searchBo.exportExl(session,response,keywords);
	}
	
}
